home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11268 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  62 lines

  1. Path: tera.mcom.com!usenet
  2. From: Daniel Malmer <malmer@netscape.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: ?? How to dump text files to screen ?? - Showit.c [01/01]
  5. Date: Fri, 22 Mar 1996 13:56:10 -0800
  6. Organization: Netscape Communications Corporation
  7. Message-ID: <315321FA.35A4@netscape.com>
  8. References: <31430CE8.469E@aol2.com> <4iddva$aic@sue.cc.uregina.ca> <314A70FF.4EC8@hsc.unt.edu> <4iocgq$kep@kryten.awinc.com>
  9. NNTP-Posting-Host: hobees.mcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.5 sun4u)
  14.  
  15. Gregory Scratchley wrote:
  16. > In article <314A70FF.4EC8@hsc.unt.edu>, Steve Fogoros <sfogoros@hsc.unt.edu>
  17. > wrote:
  18. > >Tristan Psionic wrote:
  19. > >TP>
  20. > >TP> In <31430CE8.469E@aol2.com>, Neil <neil@aol2.com> writes:
  21. > >TP> >I need help -- how can I open up a text file and just dump it
  22. > >TP> >all out (in plain text) to the screen?
  23.  
  24. How about:
  25.  
  26. #include <stdio.h>
  27. #include <errno.h>
  28.  
  29. int
  30. main(int argc, char* argv[])
  31. {
  32.   FILE* input_file;
  33.   char buf[1024];
  34.  
  35.   if ( argc != 2 ) {
  36.     fprintf(stderr, "Usage: '%s filename'\n", argv[0]);
  37.     exit(1);  
  38.   }
  39.  
  40.   if ( (input_file = fopen(argv[1], "r")) == NULL ) {
  41.     perror(argv[1]);
  42.     exit(errno);
  43.   }
  44.  
  45.   while ( fgets(buf, sizeof(buf), input_file) ) {
  46.     fputs(buf, stdout);  
  47.   }
  48.  
  49.   return 0;
  50. }
  51.  
  52. If you're on a Unix box, you can just use the "cat" command.
  53.  
  54. Dan
  55. -- 
  56. Daniel Malmer
  57. Netscape Communications Corporation
  58. malmer@netscape.com - http://home.netscape.com/people/malmer/
  59. Any opinions expressed above are mine.
  60.